import React, { PureComponent } from 'react';
import { connect } from 'dva';
import './index.css'
class contextMenu extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
        }
        this.handler = this.handler.bind(this)
    }
    componentDidMount() {
        if (this.props.onLoaded) {
            this.props.onLoaded(this);
        }
    }
    handler(e, item) {
        if (item.key == "bindStructure") {
            if (this.props.onBindStructure) {
                this.props.onBindStructure()
            }
        }
    }
    render() {
        const {
            actions,
            visible,
            left,
            top,
            close
        } = this.props;
        return (
            visible ? <ul className="handler" style={{ left: left + 'px', top: top + 'px' }}>
                {
                    actions.map((item, index) => {
                        return <li onClick={(e) => {
                            this.handler(e, item)
                        }} key={index}>{item.value}</li>
                    })
                }
                <li onClick={(e) => {
                    if (close) {
                        close()
                    }
                }}>取消</li>
            </ul> : null
        )
    }
}
export default connect(
    ({ }) => ({}),
    dispatch => ({
        updateActionData: (actionData) => dispatch({
            type: 'action/updateActionData',
            payload: actionData
        })
    })
)(contextMenu);